package com.zmn.brs.dubbo.impl.record;

import com.zmn.brs.business.interfaces.record.OperateRecordBService;
import com.zmn.brs.common.enums.EventEnum;
import com.zmn.brs.common.model.dio.StaffOperateRecordDIO;
import com.zmn.brs.common.model.mq.StaffOperateRecordMq;
import com.zmn.brs.dubbo.interfaces.record.StaffOperateEventModifyRemoteService;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.plat.dubbo.utils.DubboConsts;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 类描述：员工操作事件操作接口实现
 *
 * @author xujie
 * @since 2021/03/24 10:58
 */
@Slf4j
@Service(loadbalance = "roundrobin", timeout = 6000, retries = -1, version = DubboConsts.INTERFACE_VERSION)
public class StaffOperateEventModifyRemoteServiceImpl implements StaffOperateEventModifyRemoteService {

    private static final String TAG = "员工操作事件操作接口";

    @Resource
    OperateRecordBService staffOperateRecordBusinessService;

    @Override
    public ResponseDTO<Boolean> staffOperateEventMonitor(StaffOperateRecordDIO staffOperateRecord) {

        EventEnum event = EventEnum.getEventEnum(staffOperateRecord.getEventCode());
        if (event == null) {
            return ResponseDTO.success(false, "没匹配到对应的事件");
        }
        StaffOperateRecordMq recordMq = StaffOperateRecordMq.builder()
                .staffId(staffOperateRecord.getStaffId() + "")
                .event(event)
                .staffIp(staffOperateRecord.getStaffIp())
                .createTime(new Date())
                .build();
        boolean result = staffOperateRecordBusinessService.eventTriggering(recordMq);
        log.info("[{}],接收到新的消息message:{}", TAG, recordMq);
        return ResponseDTO.success(result);
    }
}
